/**
 * @author thaodo
 *
 *
 */
package com.mfsoft.utilities;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class Utils {
	private Context context;

	public Utils(Context context) {
		this.context = context;
	}

	// lay chieu rong man hinh
	@SuppressLint("NewApi")
	public int getScreenWidth() {
		int screenWidth;
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();

		final Point point = new Point();
		try {
			display.getSize(point);
		} catch (Exception e) {
			// thiet bi doi cu hon
			point.x = display.getWidth();
			point.y = display.getHeight();
		}
		screenWidth = point.x;
		return screenWidth;
	}
	
	@SuppressLint("NewApi")
	public int getScreenHeight(){
		int screenHeight;
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();

		final Point point = new Point();
		try {
			display.getSize(point);
		} catch (Exception e) {
			// thiet bi doi cu hon
			point.x = display.getWidth();
			point.y = display.getHeight();
		}
		screenHeight = point.y;
		return screenHeight;
	}

	public int diaInch() {
		int diaInch;
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		wm.getDefaultDisplay().getMetrics(dm);

		final int measureWidth = dm.widthPixels;
		final int measureHeight = dm.heightPixels;
		final double diagonal = Math.sqrt((measureHeight * measureHeight)
				+ (measureWidth * measureWidth));
		diaInch = (int) (diagonal/dm.densityDpi);
		return diaInch;
	}
}
